import symbolStartAnchor from '@/assets/map-ico/gisico_anchorstart.png'
import symbolEndAnchor from '@/assets/map-ico/gisico_anchorend.png'
import symbolJunction from '@/assets/map-ico/gisico_junction.png'
// import symbolPillar from '@/assets/map-ico/gisico_pillar.png'
import symbol6cDevice from '@/assets/map-ico/gisico_device_6c.png'
import symbolCrossLine from '@/assets/map-ico/gisico_device_crossLine.png'
import symbolCrossBridge from '@/assets/map-ico/gisico_device_crossBridge.png'
// import symbolBdsAt from '@/assets/map-ico/gisico_bds_ats.png'
// import symbolBdsFqs from '@/assets/map-ico/gisico_bds_fqs.png'
// import symbolBdsKbs from '@/assets/map-ico/gisico_bds_kbs.png'
import symbolBdsQybds from '@/assets/map-ico/gisico_bds_qybds.png'
import action360 from '@/assets/map-ico/360.png'
// const linkToPillarAction = {
//   title: '查看详情',
//   id: 'toPillar',
//   image: symbolPillar
// }
/**
 * intro demo
 * {
 *  attributes: {
 *      siteName: '北京站'
 *  },
 *  fieldInfos: [
 *    {
 *      fieldName: 'siteName',
 *      label: '站点'
 *    }
 *  ]
 * }
 */

/**
 * 创建铁路站点
 * @param {Array} point 站点经纬度
 * @param {Object} intro 站点属性, attributes: 基本信息, fieldInfos: 弹出框字段
 * @param {Object} view gis地图view对象
 */
export function newStationMaker(point, intro, view) {
  const textLabel = {
    geometry: {
      type: 'point',
      x: point.x,
      y: point.y,
      spatialReference: { wkid: 3857 }
    },
    symbol: {
      type: 'text',
      color: 'white',
      haloColor: 'black',
      haloSize: '1px',
      text: intro.attributes.siteName,
      xoffset: 0,
      yoffset: -20,
      font: {
        size: 12,
        family: 'sans-serif'
      }
    }
  }
  const pointGraphic = {
    geometry: {
      type: 'point',
      x: point.x,
      y: point.y,
      spatialReference: { wkid: 3857 }
    },
    symbol: {
      type: 'simple-marker',
      color: [126, 126, 126],
      size: 8,
      outline: {
        color: [255, 255, 255],
        width: 1
      }
    },
    attributes: intro.attributes,
    popupTemplate: {
      title: '{siteName}',
      content: [
        {
          type: 'fields',
          fieldInfos: intro.fieldInfos
        }
      ]
    }
  }
  view.graphics.add(pointGraphic)
  view.graphics.add(textLabel)
}

/**
 * 创建铁路区间线路
 * @param {Array} points 区间经纬度集合
 * @param {Object} intro 站点属性, attributes: 基本信息, fieldInfos: 弹出框字段
 * @param {Object} view gis地图view对象
 */
export function newStationLine(points, intro, view) {
  const polylineGraphic = {
    geometry: {
      type: 'polyline',
      paths: points,
      spatialReference: { wkid: 3857 }
    },
    symbol: {
      type: 'simple-line',
      color: [0, 137, 117],
      width: 3,
      symbolLayers: [
        {
          type: 'text',
          material: {
            color: 'black'
          },
          halo: {
            color: [255, 255, 255, 0.7],
            size: 2
          },
          size: 10
        }
      ]
    },
    attributes: intro.attributes,
    popupTemplate: {
      title: '{siteName}',
      content: [
        {
          type: 'fields',
          fieldInfos: intro.fieldInfos
        }
      ]
    }
  }
  view.graphics.add(polylineGraphic)
}

/**
 * 创建铁路锚段
 * @param {Array} points 锚段开始,结束两个端点经纬度集合
 * @param {Object} intro 站点属性, attributes: 基本信息, fieldInfos: 弹出框字段
 * @param {Object} view gis地图view对象
 */
export function newStationAnchor(points, intro, view) {
  if (points.paths && points.paths[0][0] && points.paths[0][1]) {
    const textLabelStart = {
      geometry: {
        type: 'point',
        x: points.paths[0][0][0],
        y: points.paths[0][0][1],
        spatialReference: { wkid: 3857 }
      },
      symbol: {
        type: 'text',
        color: 'white',
        haloColor: 'black',
        haloSize: '1px',
        text: intro.attributes.anchorNum,
        xoffset: 0,
        yoffset: 0,
        font: {
          size: 10,
          family: 'sans-serif'
        }
      }
    }
    const textLabelEnd = {
      geometry: {
        type: 'point',
        x: points.paths[0][1][0],
        y: points.paths[0][1][1],
        spatialReference: { wkid: 3857 }
      },
      symbol: {
        type: 'text',
        color: 'white',
        haloColor: 'black',
        haloSize: '1px',
        text: intro.attributes.anchorNum,
        xoffset: 0,
        yoffset: -5,
        font: {
          size: 10,
          family: 'sans-serif'
        }
      }
    }
    const anchorStartGraphic = {
      geometry: {
        type: 'point',
        x: points.paths[0][0][0],
        y: points.paths[0][0][1],
        spatialReference: { wkid: 3857 }
      },
      symbol: {
        type: 'picture-marker',
        url: symbolStartAnchor,
        width: '24px',
        height: '24px',
        xoffset: 0,
        yoffset: 15,
        outline: {
          style: 'solid'
        }
      },
      attributes: intro.attributes,
      popupTemplate: {
        title: '锚段开始',
        // content: [
        //   {
        //     type: 'fields',
        //     fieldInfos: intro.fieldInfos
        //   }
        // ]
        content: '<table class="esri-widget__table" summary="属性和值列表"><tbody>' +
          '<tr><th class="esri-feature__field-header" style="width: 18%;">锚段编号:</th><td class="esri-feature__field-data" style="width: 32%;">{anchorNum}</td><th class="esri-feature__field-header" style="width: 18%;">所属线路:</th><td class="esri-feature__field-data" style="width: 32%;;">{lineName}</td></tr>' +
          '<tr><th class="esri-feature__field-header" style="width: 18%;">区间站场:</th><td class="esri-feature__field-data" style="width: 32%;">{siteName}</td><th class="esri-feature__field-header" style="width: 18%;">支柱号:</th><td class="esri-feature__field-data" style="width: 32%;;">{pillarNum}</td></tr>' +
          '<tr><th class="esri-feature__field-header" style="width: 18%;">补偿类型:</th><td class="esri-feature__field-data" style="width: 32%;">{bcType}</td><th class="esri-feature__field-header" style="width: 18%;">悬挂类型:</th><td class="esri-feature__field-data" style="width: 32%;;">{xgType}</td></tr>' +
          '<tr><th class="esri-feature__field-header" style="width: 18%;">公里标:</th><td class="esri-feature__field-data" style="width: 82%;" colspan="3">{roadMark}</td></tr>' +
          '</tbody></table>',
        actions: [{
          title: ' 查看详情',
          id: 'toAnchor',
          deviceCode: intro.attributes.anchorCode,
          devClassCode: '100',
          className: 'esri-icon-browser'
        }]
      }
    }
    const anchorEndGraphic = {
      geometry: {
        type: 'point',
        x: points.paths[0][1][0],
        y: points.paths[0][1][1],
        spatialReference: { wkid: 3857 }
      },
      symbol: {
        type: 'picture-marker',
        url: symbolEndAnchor,
        width: '24px',
        height: '24px',
        xoffset: 0,
        yoffset: 15,
        outline: {
          style: 'solid'
        }
      },
      attributes: intro.attributes,
      popupTemplate: {
        title: '锚段终止',
        content: '<table class="esri-widget__table" summary="属性和值列表"><tbody>' +
          '<tr><th class="esri-feature__field-header" style="width: 18%;">锚段编号:</th><td class="esri-feature__field-data" style="width: 32%;">{anchorNum}</td><th class="esri-feature__field-header" style="width: 18%;">所属线路:</th><td class="esri-feature__field-data" style="width: 32%;;">{lineName}</td></tr>' +
          '<tr><th class="esri-feature__field-header" style="width: 18%;">区间站场:</th><td class="esri-feature__field-data" style="width: 32%;">{siteName}</td><th class="esri-feature__field-header" style="width: 18%;">支柱号:</th><td class="esri-feature__field-data" style="width: 32%;;">{pillarNum}</td></tr>' +
          '<tr><th class="esri-feature__field-header" style="width: 18%;">补偿类型:</th><td class="esri-feature__field-data" style="width: 32%;">{bcType}</td><th class="esri-feature__field-header" style="width: 18%;">悬挂类型:</th><td class="esri-feature__field-data" style="width: 32%;;">{xgType}</td></tr>' +
          '<tr><th class="esri-feature__field-header" style="width: 18%;">公里标:</th><td class="esri-feature__field-data" style="width: 82%;" colspan="3">{roadMark}</td></tr>' +
          '</tbody></table>',
        actions: [{
          title: ' 查看详情',
          id: 'toAnchor',
          deviceCode: intro.attributes.anchorCode,
          devClassCode: '100',
          className: 'esri-icon-browser'
        }]
      }
    }
    view.graphics.add(anchorStartGraphic)
    view.graphics.add(anchorEndGraphic)
    view.graphics.add(textLabelStart)
    view.graphics.add(textLabelEnd)
  }
}

/**
 * 创建铁路上下道口
 * @param {Array} point 上下道口经纬度
 * @param {Object} intro 站点属性, attributes: 基本信息, fieldInfos: 弹出框字段
 * @param {Object} view gis地图view对象
 */
export function newStationJunction(point, intro, view) {
  const textLabel = {
    geometry: {
      type: 'point',
      x: point.x,
      y: point.y,
      spatialReference: { wkid: 3857 }
    },
    symbol: {
      type: 'text',
      color: 'white',
      haloColor: 'black',
      haloSize: '1px',
      text: intro.attributes.roadJunName,
      xoffset: -15,
      yoffset: -30,
      font: {
        size: 10,
        family: 'sans-serif'
      }
    }
  }
  const junctionGraphic = {
    geometry: {
      type: 'point',
      x: point.x,
      y: point.y,
      spatialReference: { wkid: 3857 }
    },
    symbol: {
      type: 'picture-marker',
      url: symbolJunction,
      width: '24px',
      height: '24px',
      yoffset: -10,
      xoffset: -15,
      outline: {
        style: 'solid'
      }
    },
    attributes: intro.attributes,
    popupTemplate: {
      title: '上下道口',
      content: [
        {
          type: 'fields',
          fieldInfos: intro.fieldInfos
        }
      ]
    }
  }
  if (intro.attributes.panoramaAddress) {
    junctionGraphic.popupTemplate.actions = [
      {
        title: '实景图',
        id: 'showRealPicture',
        image: action360,
        panoramaAddress: intro.attributes.panoramaAddress
      }
    ]
  }
  view.graphics.add(textLabel)
  view.graphics.add(junctionGraphic)
}

/**
 * 创建交叉跨越线
 * @param {Array} point 交叉跨越线经纬度
 * @param {Object} intro 站点属性, attributes: 基本信息, fieldInfos: 弹出框字段
 * @param {Object} view gis地图view对象
 */
export function newCrossingLine(points, intro, view) {
  if (points.paths && points.paths[0][0] && points.paths[0][1]) {
    const textLabel = {
      geometry: {
        type: 'point',
        x: points.paths[0][0][0],
        y: points.paths[0][0][1],
        spatialReference: { wkid: 3857 }
      },
      symbol: {
        type: 'text',
        color: 'white',
        haloColor: 'black',
        haloSize: '1px',
        text: intro.attributes.cLineName,
        xoffset: 0,
        yoffset: -20,
        font: {
          size: 10,
          family: 'sans-serif'
        }
      }
    }
    const crossLineGraphic = {
      geometry: {
        type: 'point',
        x: points.paths[0][0][0],
        y: points.paths[0][0][1],
        spatialReference: { wkid: 3857 }
      },
      symbol: {
        type: 'picture-marker',
        url: symbolCrossLine,
        width: '24px',
        height: '24px',
        outline: {
          style: 'solid'
        }
      },
      attributes: intro.attributes,
      popupTemplate: {
        title: '交叉跨越线',
        content: '<table class="esri-widget__table" summary="属性和值列表"><tbody>' +
          '<tr><th class="esri-feature__field-header" style="width: 18%;">跨越线名称:</th><td class="esri-feature__field-data" style="width: 32%;">{cLineName}</td><th class="esri-feature__field-header" style="width: 18%;">线别:</th><td class="esri-feature__field-data" style="width: 32%;">{lineName}</td></tr>' +
          '<tr><th class="esri-feature__field-header" style="width: 18%;">区间站场:</th><td class="esri-feature__field-data" style="width: 32%;">{siteList}</td><th class="esri-feature__field-header" style="width: 18%;">公里标:</th><td class="esri-feature__field-data" style="width: 32%;">{roadMark}</td></tr>' +
          '<tr><th class="esri-feature__field-header" style="width: 18%;">支柱位置:</th><td class="esri-feature__field-data" style="width: 32%;">{pillarLocation}</td><th class="esri-feature__field-header" style="width: 18%;">电压等级:</th><td class="esri-feature__field-data" style="width: 32%;">{electricLevel}</td></tr>' +
          '</tbody></table>'
      }
    }
    view.graphics.add(textLabel)
    view.graphics.add(crossLineGraphic)
  }
}
/**
 * 创建跨线桥
 * @param {Array} point 跨线桥经纬度
 * @param {Object} intro 站点属性, attributes: 基本信息, fieldInfos: 弹出框字段
 * @param {Object} view gis地图view对象
 */
export function newCrossBridge(points, intro, view) {
  if (points.paths && points.paths[0][0] && points.paths[0][1]) {
    const textLabel = {
      geometry: {
        type: 'point',
        x: points.paths[0][0][0],
        y: points.paths[0][0][1],
        spatialReference: { wkid: 3857 }
      },
      symbol: {
        type: 'text',
        color: 'white',
        haloColor: 'black',
        haloSize: '1px',
        text: intro.attributes.bridgeName,
        xoffset: 0,
        yoffset: -20,
        font: {
          size: 10,
          family: 'sans-serif'
        }
      }
    }
    const crossBridgeGraphic = {
      geometry: {
        type: 'point',
        x: points.paths[0][0][0],
        y: points.paths[0][0][1],
        spatialReference: { wkid: 3857 }
      },
      symbol: {
        type: 'picture-marker',
        url: symbolCrossBridge,
        width: '24px',
        height: '24px',
        outline: {
          style: 'solid'
        }
      },
      attributes: intro.attributes,
      popupTemplate: {
        title: '跨线桥',
        content: '<table class="esri-widget__table" summary="属性和值列表"><tbody>' +
          '<tr><th class="esri-feature__field-header" style="width: 18%;">跨线桥名称:</th><td class="esri-feature__field-data" style="width: 32%;">{bridgeName}</td><th class="esri-feature__field-header" style="width: 18%;">线别:</th><td class="esri-feature__field-data" style="width: 32%;">{lineName}</td></tr>' +
          '<tr><th class="esri-feature__field-header" style="width: 18%;">区间站场:</th><td class="esri-feature__field-data" style="width: 32%;">{siteList}</td><th class="esri-feature__field-header" style="width: 18%;">支柱位置:</th><td class="esri-feature__field-data" style="width: 32%;">{pillarLocation}</td></tr>' +
          '<tr><th class="esri-feature__field-header" style="width: 18%;">公里标:</th><td class="esri-feature__field-data" style="width: 82%;" colspan="3">{roadMark}</td></tr>' +
          '</tbody></table>'
      }
    }
    view.graphics.add(textLabel)
    view.graphics.add(crossBridgeGraphic)
  }
}

export function newPillar(point, attr, lyr) {
  const pillarGra = {
    geometry: {
      type: 'point',
      x: point.x,
      y: point.y,
      spatialReference: { wkid: 3857 }
    },
    symbol: {
      type: 'simple-marker',
      style: 'circle',
      color: [50, 71, 101],
      size: '8px',
      outline: {
        style: 'solid',
        color: [5, 15, 34],
        width: 1
      }
    },
    attributes: attr,
    popupTemplate: {
      title: '支柱',
      content: '<table class="esri-widget__table" summary="属性和值列表"><tbody>' +
        '<tr><th class="esri-feature__field-header" style="width: 18%;">线别:</th><td class="esri-feature__field-data" style="width: 32%;;">{lineName}</td><th class="esri-feature__field-header" style="width: 18%;">区间站场:</th><td class="esri-feature__field-data" style="width: 32%;;">{siteName}</td></tr>' +
        '<tr><th class="esri-feature__field-header" style="width: 18%;">行别:</th><td class="esri-feature__field-data" style="width: 32%;;">{directionName}</td><th class="esri-feature__field-header" style="width: 18%;">支柱号:</th><td class="esri-feature__field-data" style="width: 32%;;">{pillarNum}</td></tr>' +
        '<tr><th class="esri-feature__field-header" style="width: 18%;">锚段:</th><td class="esri-feature__field-data" style="width: 32%;;">{anchorName}</td><th class="esri-feature__field-header" style="width: 18%;">支柱分类:</th><td class="esri-feature__field-data" style="width: 32%;;">{pillarType}</td></tr>' +
        '<tr><th class="esri-feature__field-header" style="width: 18%;">公里标:</th><td class="esri-feature__field-data" style="width:88%;" colspan="3">{roadMark}</td></tr>' +
        '</tbody></table>',
      actions: [{
        title: ' 查看详情',
        deviceCode: attr.pillarCode,
        devClassCode: '14',
        id: 'toPillar',
        className: 'esri-icon-browser'
      }]
    }
  }
  lyr.graphics.add(pillarGra)
  return pillarGra
}

export function newPillarLabel(point, attr, lyr) {
  const textLabel = {
    geometry: {
      type: 'point',
      x: point.x,
      y: point.y,
      spatialReference: { wkid: 3857 }
    },
    symbol: {
      type: 'text',
      color: 'white',
      haloColor: 'black',
      haloSize: '1px',
      text: attr.pillarNum,
      xoffset: 5,
      yoffset: attr.directionName === '上行' ? -10 : 5,
      font: {
        size: 10,
        family: 'sans-serif'
      }
    }
  }
  lyr.graphics.add(textLabel)
  return textLabel
}
/**
 * 创建变配电所
 * @param {Array} point 变配电所经纬度
 * @param {Object} intro 站点属性, attributes: 基本信息, fieldInfos: 弹出框字段
 * @param {Object} view gis地图view对象
 */
export function newBdsSubstation(point, intro, view) {
  const textLabel = {
    geometry: {
      type: 'point',
      x: point.x,
      y: point.y,
      spatialReference: { wkid: 3857 }
    },
    symbol: {
      type: 'text',
      color: 'white',
      haloColor: 'black',
      haloSize: '1px',
      text: intro.attributes.bdsName,
      xoffset: -10,
      yoffset: -30,
      font: {
        size: 10,
        family: 'sans-serif'
      }
    }
  }
  const bdsSubstationGraphic = {
    geometry: {
      type: 'point',
      x: point.x,
      y: point.y,
      spatialReference: { wkid: 3857 }
    },
    symbol: {
      type: 'picture-marker',
      url: symbolBdsQybds,
      width: '24px',
      height: '24px',
      xoffset: -10,
      yoffset: -10,
      outline: {
        style: 'solid'
      }
    },
    attributes: intro.attributes,
    popupTemplate: {
      title: intro.attributes.bdsName,
      content: '<table class="esri-widget__table" summary="属性和值列表"><tbody>' +
        '<tr><th class="esri-feature__field-header" style="width: 18%;">名称:</th><td class="esri-feature__field-data" style="width: 32%;">{bdsName}</td><th class="esri-feature__field-header" style="width: 18%;">线别:</th><td class="esri-feature__field-data" style="width: 32%;">{lineName}</td></tr>' +
        '<tr><th class="esri-feature__field-header" style="width: 18%;">部门:</th><td class="esri-feature__field-data" style="width: 32%;">{deptList}</td><th class="esri-feature__field-header" style="width: 18%;">所类型:</th><td class="esri-feature__field-data" style="width: 32%;">{typeName}</td></tr>' +
        '<tr><th class="esri-feature__field-header" style="width: 18%;">供电范围:</th><td colspan="3" class="esri-feature__field-data" style="width: 82%;">{supplyArea}</td></tr>' +
        '</tbody></table>'
    }
  }
  if (intro.attributes.panoramaAddress) {
    bdsSubstationGraphic.popupTemplate.actions = [
      {
        title: '实景图',
        id: 'showRealPicture',
        className: 'esri-icon-globe',
        panoramaAddress: intro.attributes.panoramaAddress
      }
    ]
  }
  view.graphics.add(textLabel)
  view.graphics.add(bdsSubstationGraphic)
}
/**
 * 创建6C设备
 * @param {Array} point 设备经纬度
 * @param {Object} intro 设备属性, attributes: 基本信息, fieldInfos: 弹出框字段
 * @param {Object} view gis地图view对象
 * @returns 地图图形对象
 */
export function new6cDevice(point, intro, view) {
  const textLabel = {
    geometry: {
      type: 'point',
      x: point.x,
      y: point.y,
      spatialReference: { wkid: 3857 }
    },
    symbol: {
      type: 'text',
      color: 'white',
      haloColor: 'black',
      haloSize: '1px',
      text: intro.attributes.deviceName,
      xoffset: 0,
      yoffset: -20,
      font: {
        size: 10,
        family: 'sans-serif'
      }
    }
  }
  const polylineGraphic = {
    geometry: {
      type: 'point',
      x: point.x,
      y: point.y,
      spatialReference: { wkid: 3857 }
    },
    symbol: {
      type: 'picture-marker',
      url: symbol6cDevice,
      width: '24px',
      height: '24px',
      outline: {
        style: 'solid'
      }
    },
    attributes: intro.attributes,
    popupTemplate: intro.fieldInfos ? {
      title: '{deviceName}',
      content: [
        {
          type: 'fields',
          fieldInfos: intro.fieldInfos
        }
      ]
    } : null
  }
  view.graphics.add(polylineGraphic)
  view.graphics.add(textLabel)
  return polylineGraphic
}

/**
 * 创建关键设备
 * @param {Array} point 设备经纬度
 * @param {Object} intro 设备属性, attributes: 基本信息, fieldInfos: 弹出框字段
 * @param {Object} view gis地图view对象
 * @returns 地图图形对象
 */
export function newJcwDevice(point, intro, view) {
  const polylineGraphic = {
    geometry: {
      type: 'point',
      x: point.x,
      y: point.y,
      spatialReference: { wkid: 3857 }
    },
    symbol: {
      type: 'picture-marker',
      url: require('@/assets/map-ico/gisico_device_' + intro.attributes.devClassCode + '.png'),
      width: '24px',
      height: '24px',
      outline: {
        style: 'solid'
      }
    },
    attributes: intro.attributes,
    popupTemplate: intro.fieldInfos ? {
      title: '{devClassName} - {deviceName}',
      // content: [
      //   {
      //     type: 'fields',
      //     fieldInfos: intro.fieldInfos
      //   }
      // ],
      content: '<table class="esri-widget__table" summary="属性和值列表"><tbody>' +
        '<tr><th class="esri-feature__field-header" style="width: 18%;">线别:</th><td class="esri-feature__field-data" style="width: 32%;;">{lineName}</td><th class="esri-feature__field-header" style="width: 18%;">区间站场:</th><td class="esri-feature__field-data" style="width: 32%;;">{siteName}</td></tr>' +
        '<tr><th class="esri-feature__field-header" style="width: 18%;">设备名称:</th><td class="esri-feature__field-data" style="width: 32%;;">{deviceName}</td><th class="esri-feature__field-header" style="width: 18%;">设备类型:</th><td class="esri-feature__field-data" style="width: 32%;;">{devClassName}</td></tr>' +
        '<tr><th class="esri-feature__field-header" style="width: 18%;">检修周期:</th><td class="esri-feature__field-data" style="width: 32%;;">{repairInfo}</td><th class="esri-feature__field-header" style="width: 18%;">检测周期:</th><td class="esri-feature__field-data" style="width: 32%;;">{detectInfo}</td></tr>' +
        '<tr><th class="esri-feature__field-header" style="width: 18%;">巡视周期:</th><td class="esri-feature__field-data" style="width: 32%;;">{tourInfo}</td><th class="esri-feature__field-header" style="width: 18%;"></th><td class="esri-feature__field-data" style="width: 32%;;"></td></tr>' +
        '</tbody></table>',
      actions: [{
        title: ' 查看详情',
        deviceCode: intro.attributes.deviceCode,
        devClassCode: intro.attributes.devClassCode,
        id: 'toPillar',
        className: 'esri-icon-browser'
      }]
    } : null
  }
  view.graphics.add(polylineGraphic)
  return polylineGraphic
}

/**
 * 打开设备看板页面
 * @param {(string)} devClassCode 设备类型编码
 * @param {(string)} deviceCode 设备编码
 * @param {(boolean)} isNewpage 是否打开新窗口
 */
export const openDevicePage = function(devClassCode, deviceCode, isNewpage) {
  // setTimeout(_ => {
  let url = ''
  if (devClassCode === '100') {
    url = '/phm/anchor?devClassCode=' + devClassCode + '&deviceCode=' + deviceCode
  } else if (devClassCode === '14') {
    url = '/phm/pillar?devClassCode=' + devClassCode + '&deviceCode=' + deviceCode
  } else {
    url = '/phm/device?devClassCode=' + devClassCode + '&deviceCode=' + deviceCode
  }
  if (isNewpage) {
    window.open(url, '_blank')
  } else {
    return new Promise(resolve => {
      resolve({ url: url })
    })
  }
  // }, 500)
}
/**
 * 转换地图范围坐标系
 * @param {(string)} devClassCode 设备类型编码
 * @param {(string)} deviceCode 设备编码
 */
export const mercToLonlat = function(etx) {
  const xmin = etx.xmin / 20037508.34 * 180
  const xmax = etx.xmax / 20037508.34 * 180
  let ymin = etx.ymin / 20037508.34 * 180
  let ymax = etx.ymax / 20037508.34 * 180
  ymin = 180 / Math.PI * (2 * Math.atan(Math.exp(ymin * Math.PI / 180)) - Math.PI / 2)
  ymax = 180 / Math.PI * (2 * Math.atan(Math.exp(ymax * Math.PI / 180)) - Math.PI / 2)
  return {
    xmin,
    xmax,
    ymin,
    ymax
  }
}
